var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/antd/tree.tsx
var tree_exports = {};
__export(tree_exports, {
  Tree: () => Tree,
  TreeLoading: () => TreeLoading,
  TreeSelect: () => TreeSelect
});
module.exports = __toCommonJS(tree_exports);
var import_antd = require("antd");
var import_react = require("react");
var import_util = require("../../util");
var import_widgets = require("../../widgets");
var { DirectoryTree } = import_antd.Tree;
function TreeLoading({ row = 4, style }) {
  return /* @__PURE__ */ React.createElement("div", { style: { padding: 5, ...style } }, /* @__PURE__ */ React.createElement(import_antd.Skeleton, { active: true, paragraph: { rows: 1 }, title: false }), /* @__PURE__ */ React.createElement("div", { style: { paddingLeft: 20 } }, /* @__PURE__ */ React.createElement(import_antd.Skeleton, { active: true, paragraph: { rows: row }, title: false })));
}
var Tree = (0, import_util.compHoc)(
  ({
    outRef,
    height,
    nowrap = true,
    virtual = true,
    className,
    directoryTree = true,
    rowChecked = false,
    ...props
  }) => {
    const [treeHeight, setTreeHeight] = (0, import_react.useState)(height);
    const [selectedKeys, setSelectedKeys] = (0, import_react.useState)(props.defaultSelectedKeys || []);
    const onResize = (0, import_util.useRefCallback)(({ height: height2 }) => {
      setTreeHeight(height2);
    });
    const extraProps = {};
    if (rowChecked) {
      extraProps.onSelect = (keys, info) => {
        var _a;
        const eventNode = info.node;
        if (props.checkable && eventNode && !eventNode.disabled && eventNode.checkable !== false && !eventNode.disableCheckbox) {
          outRef.current.onNodeCheck({}, info.node, true);
        }
        (_a = props.onSelect) == null ? void 0 : _a.call(props, keys, info);
      };
    }
    if (!props.checkable && directoryTree) {
      extraProps.onSelect = (keys, info) => {
        var _a;
        const realKeys = JSON.stringify(keys) === JSON.stringify(selectedKeys) ? [] : keys;
        const realInfo = JSON.stringify(keys) === JSON.stringify(selectedKeys) ? Object.assign({}, info, { selectedNodes: [], node: {} }) : info;
        setSelectedKeys(realKeys);
        (_a = props.onSelect) == null ? void 0 : _a.call(props, realKeys, realInfo);
      };
      extraProps.selectedKeys = selectedKeys;
    }
    const RenderTree = directoryTree ? DirectoryTree : import_antd.Tree;
    if (virtual) {
      return /* @__PURE__ */ React.createElement(
        "div",
        {
          className: import_util.iup.classNames("virtual-tree", { "iup-tree-nowrap": nowrap }, className),
          style: {
            height: height || "100%",
            overflow: `hidden`,
            width: "100%",
            minHeight: 60,
            position: "relative",
            backgroundColor: import_util.cssVar.componentColor
          }
        },
        height ? /* @__PURE__ */ React.createElement(RenderTree, { ref: outRef, expandAction: "doubleClick", blockNode: true, ...props, ...extraProps, height }) : /* @__PURE__ */ React.createElement(import_widgets.AutoResize, { onResize }, !!treeHeight && /* @__PURE__ */ React.createElement(
          RenderTree,
          {
            ref: outRef,
            expandAction: "doubleClick",
            blockNode: true,
            ...props,
            ...extraProps,
            height: treeHeight
          }
        ))
      );
    }
    return /* @__PURE__ */ React.createElement(
      "div",
      {
        className: import_util.iup.classNames({ "iup-tree-nowrap": nowrap }, className),
        style: { height: height || "100%", width: "100%", position: "relative", overflow: "auto" }
      },
      /* @__PURE__ */ React.createElement(RenderTree, { ref: outRef, expandAction: "doubleClick", blockNode: true, virtual: false, ...props, ...extraProps })
    );
  }
);
var TreeSelect = (0, import_util.compHoc)(({ outRef, ...props }) => {
  return /* @__PURE__ */ React.createElement(import_antd.TreeSelect, { ref: outRef, ...props });
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Tree,
  TreeLoading,
  TreeSelect
});
